public class Solution1 {
    public void sortColors(int[] nums) {
        int i = 0;
        int left = -1;
        int right = nums.length;

        while(i < right) {
            if(nums[i] == 0) {
                swap(nums, ++left, i++);
            }else if(nums[i] == 1) {
                i++;
            }else {
                swap(nums, --right, i);
            }
        }
    }

    public void swap(int[] nums, int left, int right) {
        int temp = nums[left];
        nums[left] = nums[right];
        nums[right] = temp;
    }
}
